package com.gettec.lims.client.components;

import java.util.List;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.gettec.lims.client.NlimsConstants;
import com.gettec.lims.client.grid.RegSheetGridView;
import com.gettec.lims.client.grid.SampleInfoGridView;
import com.gettec.lims.client.menu.MenuItemEx;
import com.gettec.lims.client.menu.MenuListener;
import com.gettec.lims.client.services.NnimsServiceAsync;
import com.gettec.lims.shared.model.ComBoModel;
import com.gettec.lims.shared.model.SysUser;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class NavigationPanel extends ContentPanel   
{  
	
	
    public NavigationPanel()   
    { 
       final NnimsServiceAsync service=Registry.get(NlimsConstants.SERVICE);
	   	
  	   /*service.getUserList(new AsyncCallback<List<SysUser>> (){

  	   		@Override
  	   		public void onFailure(Throwable caught) {}

  	   		@Override
  	   		public void onSuccess(List<SysUser> result) {
  	   //	List<SysUser> result=service.getUserList();
  	   		 
  	   		 BeanModelFactory factory = BeanModelLookup.get().getFactory(SysUser.class);
  	   		ListStore<BeanModel> ls=new ListStore<BeanModel>();
  			   for (int i = 0; i <result.size(); i++) {
  			    	BeanModel model = factory.createModel(result.get(i));
  			    	ls.add(model);
  				}
  			  Registry.register("storerrr", ls);
  			  System.out.println(Registry.get("storerrr").toString());     
  	   	}}); */
  	   //-----------------------------------------------
  /*	 RpcProxy<ListLoadResult<SysUser>> proxy = new RpcProxy<ListLoadResult<SysUser>>() {
			

			@Override
			protected void load(Object loadConfig,
					AsyncCallback<ListLoadResult<SysUser>> callback) {
				// TODO Auto-generated method stub
				service.getUserList(callback);
			}
		};*/
		  RpcProxy<List<SysUser>> proxy = new RpcProxy<List<SysUser>>() {  
			            @Override  
			            protected void load(Object loadConfig,  
			                      AsyncCallback<List<SysUser>> callback) {  
			            	service.getUserList(callback);  
			    
			             }  
			         };  
			         BeanModelReader reader = new BeanModelReader();  
   ListLoader<ListLoadResult<BeanModel>> loader = new BaseListLoader<ListLoadResult<BeanModel>>(proxy, reader);  
			         //4：传入loader，生成store，此时还没有load数据   
			         ListStore<BeanModel> suStore = new ListStore<BeanModel>(loader);  
			         //5：将stroe绑定到data-backed component身上   
			         //feedList.setStore(feedStore);  
			       //  feedList.setDisplayField("title");  
			         //6：真正的load数据，
			         loader.load();  
			   
			       //  add(feedList);  
			  


  	   //-----------------------------------------------
  	 //setSpacing(2);
  	/* ListStore <ComBoModel> store = new ListStore <ComBoModel> ();  
	    store.add (new ComBoModel ("Android", "0"));  
	    store.add (new ComBoModel ("Smart","1"));  
	    store.add (new ComBoModel ("Google","2"));  */
	    //初始化Combobox  
	    
    
  	 Menu menu = new Menu();   
     
     MenuItemEx item1 = new MenuItemEx("委托登记单");  
     item1.addSelectionListener(new SelectionListener<MenuEvent>()
    		 {

				@Override
				public void componentSelected(MenuEvent ce) {
					// TODO Auto-generated method stub
					RegSheetGridView r=new RegSheetGridView();
					r.show();
				}
    	 
    		 });
     menu.add(item1);   
      item1 = new MenuItemEx("样品信息登记");  
     item1.addSelectionListener(new SelectionListener<MenuEvent>()
    		 {

				@Override
				public void componentSelected(MenuEvent ce) {
					// TODO Auto-generated method stub
					SampleInfoGridView r=new SampleInfoGridView();
					r.show();
				}
    	 
    		 });
   //  item1.addSelectionListener(new MenuListener());
     menu.add(item1);  
     MenuItemEx item3 = new MenuItemEx("分派检测复核人员");  
     item3.addSelectionListener(new MenuListener());
     menu.add(item3);  
     MenuItemEx item4 = new MenuItemEx("填写原始记录");  
     item4.addSelectionListener(new MenuListener());
     menu.add(item4);  
     MenuItemEx item5 = new MenuItemEx("审核原始记录");  
     item5.addSelectionListener(new MenuListener());
     menu.add(item5);
     //menu.setLayoutData(new FitLayout());
    
    // add(menu);
     
     ComboBox <BeanModel> combobox = new ComboBox <BeanModel> ();  
	    combobox.setTriggerAction (TriggerAction.ALL);
	    combobox.setEmptyText("请选择在线用户...");   
	    combobox.setDisplayField ("name");  
	   // combobox.setValue(value)
	    combobox.setLayoutData(new FitLayout());
	    combobox.setValueField ("value");  
	    combobox.setStore (suStore); 
	   
	   // add(combobox,new BorderLayoutData(LayoutRegion.SOUTH)); 
	   
	  
	    LayoutContainer top = new LayoutContainer();
	    top.add(menu);
	    top.setHeight(130);
	    LayoutContainer buttom = new LayoutContainer();
	    buttom.add(combobox);
	     add(top);
         add(buttom);
     //ContentPanel panel = new ContentPanel();  
    /* MenuBar bar = new MenuBar();   
     bar.add(new MenuBarItem("文件", menu));   */
   //  panel.setHeading("一般业务");   
    // panel.setTopComponent(menu);   
     
  
    // add(panel, new FlowData(10)); 
 	//---------------------------------------------------------------
    /* final Button regbtn = new Button("委托登记");  
     ToolTipConfig createNewToolTipConfig = new ToolTipConfig();  
     createNewToolTipConfig.setTitle("工作单登记");  
     createNewToolTipConfig.setText("录入工间单信息");  
     regbtn.setToolTip(createNewToolTipConfig);  
     regbtn  
     .addSelectionListener(new SelectionListener<ButtonEvent>() {
			@Override
			 public void componentSelected(ButtonEvent ce) {  
				createRegSheetWindow();  
			    }  
 });  */
   //---------------------------------------------------------------
     //final Button si_btn = new Button("样品信息登记");  
    /* 
     si_btn  .addSelectionListener(new SelectionListener<ButtonEvent>() {
			@Override
			 public void componentSelected(ButtonEvent ce) {  
				createSampleInfoWindow();  
			    } 
			});*/
  
     //---------------------------------------------------------------------
    // Button regsheet=new Button("委托登记菜单");
     /*ComboBox  bb=new ComboBox();
     ListStore store=new ListStore();
     store.add(new SysUser);
     bb.setFieldLabel("测试");
     bb.setEmptyText("快");
     add(bb);*/
		     // combox.setValue(ls.getAt(0));
		       
		  

   //测试ComboBox的代码
   
   
     
 
   /* SimpleComboBox<String> cboUsed = new SimpleComboBox<String>();  
    cboUsed.setFieldLabel("使用情况");  
    cboUsed.setEditable(true);  
    cboUsed.add("未使用");  
    cboUsed.add("使用");  
    
   // cboUsed.setSimpleValue("--*---");
    add(cboUsed); */
    /* ListStore<BeanModel> states = new ListStore<BeanModel>();   
     states.add(TestData.getUsers());   
   
     ComboBox<BeanModel> combo = new ComboBox<BeanModel>();   
     combo.setEmptyText("请选择在线用户...");   
     combo.setDisplayField("name");   
     combo.setValueField("id");
     combo.setWidth(150);   
     combo.setStore(states);   
     combo.setTypeAhead(true);   
     combo.setFieldLabel("当前在线用户");
     combo.setTitle("当前在线用户");
     combo.setTriggerAction(TriggerAction.ALL);   
    add(combo);   
			   	 add(regbtn); 
			   	 add(si_btn);                                  
	*/
    }  
   
    @Override
	protected void onRender(Element parent, int pos) 
    {
		super.onRender(parent, pos);

		
		 
	}
	
   
}  